from fastapi import Depends
from redis.asyncio import Redis
from motor.motor_asyncio import AsyncIOMotorClient,AsyncIOMotorDatabase

from app.db.redis import get_redis
from app.db.mongo import get_mongo

class UserService:
    def __init__(self, redis: Redis = Depends(get_redis), mongo:AsyncIOMotorClient = Depends(get_mongo)):
        self._redis = redis
        self._db:AsyncIOMotorDatabase = mongo.get_database["test"]
    
    async def get_user(self, user_id: str) -> dict:
        try:
            self._db.get_collection("ddd").insert_one()
            await self.redis.set(f"user:{user_id}", "data666")
            data = await self._redis.get(f"user:{user_id}")
            print(f"return {data}")
            return data
        except Exception as exc:
            print(f"something wrong {exc}")
